解法 = set()

def 二十四点(各数):
    if len(各数) == 1:
        if abs(eval(各数[0]) - 24) < 1e-5:
            解法.add(各数[0])
    else:
        for i in range(len(各数)):
            for j in range(i+1, len(各数)):
                余下各数 = [x for p, x in enumerate(各数) if p != i and p != j]
                for 运算 in "+-*/":
                    if 运算 in "+-*" or eval(str(各数[j])) != 0:
                        二十四点(["("+ str(各数[i]) + 运算 + str(各数[j]) + ")"] + 余下各数)
                    if 运算 == "-" or (运算 == "/" and eval(str(各数[i])) != 0):
                        二十四点(["("+ str(各数[j]) + 运算 + str(各数[i]) + ")"] + 余下各数)








#二十四点([3, 7, 9, 13]) # 测试用例 [1, 6, 7, 9]
二十四点([8, 8, 3, 3])
#print("%d 种解法." %len(解法))
for i, s in enumerate(解法):
    print(str(i+1) + ": " + str(s) + " = 24")
    #print("%d: %s = 24" %(i+1, s))
